<?php
/**
 *  
 *
  */
namespace Org\Util;
class Rhk6 {

    
     public function hk6_balance() {
		 $day=date("Y-m-d");
		 $day_time=strtotime($day);
		 $insert_data=array();
		 $lm=array();
		// foreach($open_time as $k=>$v){
// 				  $kj_time[$k]=strtotime($day.' '.$v['kj_time']);
				  $n_time=time(); 
				 // if($n_time>$kj_time[$k]&&$n_time<$kj_time[$k]+60*3){  //根据后台开始将时间之后3分钟内不停的获取开奖数据
				    $condition['c_id']=12;	
					//$condition['add_time'] = array(array('gt',$day_time)) ; 
 					$max_c_no=M('lottery_results')->where($condition)->max('c_no'); //获取当天最大期数
					
					
					$url='http://a.apiplus.net/newly.do?token=5ee5aca63461f954&code=hk6&rows=1&format=json'; //接口地址
					
					$new_result=get_http($url);
					$result=json_decode($new_result,true);
					
					// print_r($result['data']);exit;
				
					if($max_c_no!=$result['data'][0]['expect']){
				 	// print_r($result['data'][0]['expect']);exit;
					$result['data'][0]['opencode']=strtr($result['data'][0]['opencode'],'+',',');
					S('hk6_'.$result['data'][0]['expect'],$result['data'][0]['opencode']);  //存入缓存  方便计算两面长龙算法
					$insert_data['c_no']=$result['data'][0]['expect'];
					$insert_data['c_id']=12;
					$insert_data['c_name']='香港六合彩';
					$insert_data['add_time']=$result['data'][0]['opentimestamp'];
					
					
					
					$insert_data['status']=0;
					$num= explode(",",$result['data'][0]['opencode']);
					
					$insert_data['lottery_result']=implode(',',$num);
				
					$sum=array_sum($num);
					
					$n_lm=$this->zh_zodiac($num);//生肖
					
					$insert_data['lm']=$n_lm;
					if($max_c_no+1==$result['data'][0]['expect']){  //计算两面长龙结果
					  
					  $bdx=$this->bdx($num); //正码大小
					  $bds=$this->bds($num); //正码单双 
					  $bds_h=$this->bds_h($num); //正码合数单双 
					  $bdx_h=$this->bdx_h($num); //正码合数大小 
					  $color=$this->color($num); //正码波色 
					  $animal_ds=$this->animal_ds($n_lm);//总生肖单双
					  $te_sx=$this->te_sx($n_lm);//天地生肖
					   $qi_se=$this->qi_se($num);//七色波
					   $te_jq=$this->te_jq($n_lm);//特码家禽野兽
					   $bdx_w=$this->bdx_w($num);//尾大小
 					   $flag=1;
 					
					     
					    for($i=1;$i<=7;$i++){
						  $strds='flag_bds'.$i;
					      $$strds=0;
						  
						  $strds='flag_bds_h'.$i;
					      $$strds=0;
						   
						  $strdx='flag_bdx'.$i;
					      $$strdx=0;
						   $strdx='flag_bdx_w'.$i;
					      $$strdx=0;
						  $strdx='flag_bdx_h'.$i;
					      $$strdx=0;
						  
						  $strdcolor='flag_color'.$i;
					      $$strdcolor=0;
						  
						 
					   }
					   $flag_te_sx=0;$flag_animal=0;$flag_zds=0;$flag_zdx=0;
					   $flag_qsb=0;
					   $flag_jq=0;
					   $k=1;
					   $kk=1;
					   do{
						   
						   $old_lottery=$result['data'][0]['expect']-$k;
						   //S('bjpk10_'.$old_lottery,NULL);
						   $cqnc_result=S('hk6_'.$old_lottery);
							
							if(empty($cqnc_result))
							{
							$condition1['c_id']=12;
							$condition1['c_no']=$old_lottery;
							$cqnc_result1=M('lottery_results')->where($condition1)->getField('lottery_result');
							if($cqnc_result1){
							S('hk6_'.$old_lottery,$cqnc_result1);
							}else{
								$flag=0;
								}
							}	
						 
 						   $num1[$k-1]= explode(",",$cqnc_result);
						  $sum1[$k-1]=array_sum($num1[$k-1]);
						 
						  //正码单双
						 $bds1=$this->bds($num1[$k-1]);
						
						 for($i=1;$i<=7;$i++){
						  $str='flag_bds'.$i;
						  $str1='b_ds'.$i;	
						  switch ($i)
							{
							 case 1:$gread='正码1';
							 break;
							 case 2:$gread='正码2';
							 break;
							 case 3:$gread='正码3';
							 break;
							 case 4:$gread='正码4';
							 break;
							 case 5:$gread='正码5';
							 break;
							 case 6:$gread='正码6';
							 break;
							  case 7:$gread='特码';
							 break;
						
							  default:
 									break;
								
							  }
						   if($$str==0){
							   $ab=$i-1;
							  if($bds1[$ab]==$bds[$ab]){
								 
							   $b=$k+1;
								 if($bds1[$ab]=='双'){
								
								  if($i==7){
										
										   $$str1='DS=S,'.$b.','.$gread.'-双';
									 }else{
										 $$str1='ZMDS'.$i.'=S,'.$b.','.$gread.'-双';
									 }
								 }else{
									 if($i==7){
										
										   $$str1='DS=D,'.$b.','.$gread.'-单';
									 }else{
										 $$str1='ZMDS'.$i.'=D,'.$b.','.$gread.'-单';
									 }
								
									 }
							   }else{
							   $$str=1;	 
								   }
						   }
						  }
						   
						  $bdx1=$this->bdx($num1[$k-1]);
						//正码大小
						 for($i=1;$i<=7;$i++){
						  $str2='flag_bdx'.$i;
						  $str3='b_dx'.$i;	
						  switch ($i)
							{
							 case 1:$gread='正码1';
							 break;
							 case 2:$gread='正码2';
							 break;
							 case 3:$gread='正码3';
							 break;
							 case 4:$gread='正码4';
							 break;
							 case 5:$gread='正码5';
							 break;
							 case 6:$gread='正码6';
							 break;
							  case 7:$gread='特码';
							 break;
							  default:
 									break;
								
							  }
						   if($$str2==0){
							   $ab=$i-1;
							  if($bdx1[$ab]==$bdx[$ab]){
								 
							   $b=$k+1;
								 if($bdx1[$ab]=='小'){
									 if($i==7){
										  $$str3='DX=X,'.$b.','.$gread.'-小';
									 }else{
										 $$str3='ZMDX'.$i.'=X,'.$b.','.$gread.'-小'; 
									 }
								
								 }else{
									  if($i==7){
										 $$str3='DX=D,'.$b.','.$gread.'-大';
									 }else{
										 $$str3='ZMDX'.$i.'=D,'.$b.','.$gread.'-大';
									 }
								 
									 }
							   }else{
							   $$str2=1;	 
								   }
						   }
						  } 
						 
						   //合大小
						    $bdx1_h=$this->bdx_h($num1[$k-1]);
					
						 for($i=1;$i<=7;$i++){
						  $str4='flag_bdx_h'.$i;
						  $str5='b_dx_h'.$i;	
						  switch ($i)
							{
							  case 1:$gread='正码1';
							 break;
							 case 2:$gread='正码2';
							 break;
							 case 3:$gread='正码3';
							 break;
							 case 4:$gread='正码4';
							 break;
							 case 5:$gread='正码5';
							 break;
							 case 6:$gread='正码6';
							 break;
							  case 7:$gread='特码';
							 break;
							  default:
 									break;
								
							  }
						     if($$str4==0){
							   $ab=$i-1;
							  if($bdx1_h[$ab]==$bdx_h[$ab]){
								 
							   $b=$k+1;
								 if($bdx1_h[$ab]=='合小'){
								
								  if($i==7){
										 
										  $$str5='HDX=X,'.$b.','.$gread.'-合小';
									 }else{
										
										 $$str5='ZHDX'.$i.'=X,'.$b.','.$gread.'-合小';
									 }
								 }else{
									 
									   if($i==7){
										 
										  $$str5='HDX=D,'.$b.','.$gread.'-合大';
									 }else{
										
										 $$str5='ZHDX'.$i.'=D,'.$b.','.$gread.'-合大';
									 }
								 
									 }
							   }else{
							   $$str4=1;	 
								   }
						   }
						  } 
						
						
						
						  //合数单双
						    $bds1_h=$this->bds_h($num1[$k-1]);
						
						 for($i=1;$i<=7;$i++){
						  $str6='flag_bds_h'.$i;
						  $str7='b_ds_h'.$i;	
						  switch ($i)
							{
							  case 1:$gread='正码1';$name='ZHDS';
							 break;
							 case 2:$gread='正码2';$name='ZHDS';
							 break;
							 case 3:$gread='正码3';$name='ZHDS';
							 break;
							 case 4:$gread='正码4';$name='ZHDS';
							 break;
							 case 5:$gread='正码5';$name='ZHDS';
							 break;
							 case 6:$gread='正码6';$name='ZHDS';
							 break;
							  case 7:$gread='特码';$name='YHDS';
							 break;
							  default:
 									break;
								
							  }
						    if($$str6==0){
							   $ab=$i-1;
							  if($bds1_h[$ab]==$bds_h[$ab]){
								 
							   $b=$k+1;
								 if($bds_h[$ab]=='合双'){
								 $$str7=$name.$i.'=S,'.$b.','.$gread.'-合双';
								 }else{
								 $$str7=$name.$i.'=D,'.$b.','.$gread.'-合单';
									 }
							   }else{
							   $$str6=1;	 
								   }
						   }
						  } 
						  
						   //波色
						    $color1=$this->color($num1[$k-1]);
						
						 for($i=1;$i<=7;$i++){
						  $str8='flag_color'.$i;
						  $str9='b_color'.$i;	
						  switch ($i)
							{
							  case 1:$gread='正码1';$name='ZMSB';
							 break;
							 case 2:$gread='正码2';$name='ZMSB';
							 break;
							 case 3:$gread='正码3';$name='ZMSB';
							 break;
							 case 4:$gread='正码4';$name='ZMSB';
							 break;
							 case 5:$gread='正码5';$name='ZMSB';
							 break;
							 case 6:$gread='正码6';$name='ZMSB';
							 break;
							  case 7:$gread='特码';$name='SB';
							 break;
							
							  default:
 									break;
								
							  }
						    if($$str8==0){
							   $ab=$i-1;
							  if($color[$ab]==$color1[$ab]){
								 
							   $b=$k+1;
								 if($color1[$ab]=='红波'){
								 $$str9=$name.$i.'=R,'.$b.','.$gread.'-红波';
								 }elseif($color1[$ab]=='蓝波'){
									  $$str9=$name.$i.'=B,'.$b.','.$gread.'-蓝波';
								 }else{
								 $$str9=$name.$i.'=G,'.$b.','.$gread.'-绿波';
									 }
							   }else{
							   $$str8=1;	 
								   }
						   }
						  } 
						  
						  
						  //尾大小
						    $bdx1_w=$this->bdx_w($num1[$k-1]);
					
						 for($i=1;$i<=7;$i++){
						  $str10='flag_bdx_w'.$i;
						  $str11='b_dx_w'.$i;	
						  switch ($i)
							{
							  case 1:$gread='正码1';
							 break;
							 case 2:$gread='正码2';
							 break;
							 case 3:$gread='正码3';
							 break;
							 case 4:$gread='正码4';
							 break;
							 case 5:$gread='正码5';
							 break;
							 case 6:$gread='正码6';
							 break;
							  case 7:$gread='特码';
							 break;
							  default:
 									break;
								
							  }
						     if($$str10==0){
							   $ab=$i-1;
							  if($bdx1_w[$ab]==$bdx_w[$ab]){
								 
							   $b=$k+1;
								 if($bdx1_w[$ab]=='尾小'){
								
								  if($i==7){
										 
										  $$str11='WX=X,'.$b.','.$gread.'-尾小';
									 }else{
										
										 $$str11='ZMWDX'.$i.'=X,'.$b.','.$gread.'-尾小';
									 }
								 }else{
									 
									   if($i==7){
										 
										  $$str11='WX=D,'.$b.','.$gread.'-尾大';
									 }else{
										
										 $$str11='ZMWDX'.$i.'=D,'.$b.','.$gread.'-尾大';
									 }
								 
									 }
							   }else{
							   $$str10=1;	 
								   }
						   }
						  } 
						
						
						 
						    //计算总和单双两面长龙
						   $ds1=$this->zh_ds($sum1[$k-1]);
						   if($flag_zds==0){
							   
							  if($ds1==$this->zh_ds($sum)){
							   $b=$k+1;
							   //ZDS=D,2,总和单
								 if($ds1=='双'){
								 $zh_ds='ZDS=S,'.$b.',总和双';
								 }else{
								 $zh_ds='ZDS=D,'.$b.',总和单';
									 }
							   }else{
							   $flag_zds=1;	 
								   }
						   }
						    //计算总和大小两面长龙
						   $dx1=$this->zh_dx($sum1[$k-1]);
						   if($flag_zdx==0){
							   
							  if($dx1==$this->zh_dx($sum)){
							   $b=$k+1;
							   //ZDS=D,2,总和单
								 if($dx1=='小'){
								 $zh_dx='ZDX=X,'.$b.',总和小';
								 }else{
										// $zh_dx='ZDX=H,'.$b.',总和和'; 
										  $zh_dx='ZDX=D,'.$b.',总和大';
									 }
							   }else{
							   $flag_zdx=1;	 
								   }
						   }
						   
						    //计算特码天地生肖两面长龙
						   $te_sx1=$this->te_sx($this->zh_zodiac($num1[$k-1])); 
						   
						   if($flag_te_sx==0){
							   
							  if($te_sx1==$te_sx){
							   $b=$k+1;
							   //ZDS=D,2,总和单
								 if($te_sx1=='地'){
								 $te_sx_td='TSX=D,'.$b.',特码-地肖';
								 }else{
										 $te_sx_td='TSX=T,'.$b.',特码-天肖';
										
									 }
							   }else{
							   $flag_te_sx=1;	 
								   }
						   }
						  
						     //计算特码家禽野兽两面长龙
						   $te_jq1=$this->te_jq($this->zh_zodiac($num1[$k-1]));
						   if($flag_jq==0){
							   
							  if($te_jq1==$te_jq){
							   $b=$k+1;
							   //ZDS=D,2,总和单
								 if($te_jq1=='家禽'){
								 $te_sx_jq='JQYS=JQ,'.$b.',特码-家禽';
								 }else{
										 $te_sx_jq='JQYS=YS,'.$b.',特码-野兽';
										
									 }
							   }else{
							   $flag_jq=1;	 
								   }
						   }
						     
						    //计算七色波两面长龙
						   $qi_se1=$this->qi_se($num1[$k-1]);
						   if($flag_qsb==0){
							   
							  if($qi_se1==$qi_se){
							   $b=$k+1;
							   
								 if($qi_se1=='红波'){
								 $qisebo='QSB=R,'.$b.',七色波-红波';
								 }elseif($qi_se1=='蓝波'){
									 $qisebo='QSB=B,'.$b.',七色波-蓝波';
								 }else{
										 $qisebo='QSB=G,'.$b.',七色波-绿波';
										
									 }
							   }else{
							   $flag_qsb=1;	 
								   }
						   }
						 
						   
						   
						     //计算总生肖单双两面长龙
						   $animal_ds1=$this->animal_ds($this->zh_zodiac($num1[$k-1]));
						   if($flag_animal==0){
							   
							  if($animal_ds1==$animal_ds){
							   $b=$k+1;
							   //ZDS=D,2,总和单
								 if($animal_ds1=='单'){
								 $zh_sx_ds='ZSXDS=D,'.$b.',总肖单双-单';
								 }else{
										$zh_sx_ds='ZSXDS=S,'.$b.',总肖单双-双';
									 }
							   }else{
							   $flag_animal=1;	 
								   }
						   }
						 
						 
						 $k++;	 
					      $sss1='flag_bds1';
						  $sss2='flag_bds2';
						  $sss3='flag_bds3';
						  $sss4='flag_bds4';
						  $sss5='flag_bds5';
						  $sss6='flag_bds6';
						  $sss7='flag_bds7';
						  
						 
						  
						  $xxx1='flag_bdx1';
						  $xxx2='flag_bdx2';
						  $xxx3='flag_bdx3';
						  $xxx4='flag_bdx4';
						  $xxx5='flag_bdx5';
						  $xxx6='flag_bdx6';
						  $xxx7='flag_bdx7';
						
						  
						  $sss1_h='flag_bds_h1';
						  $sss2_h='flag_bds_h2';
						  $sss3_h='flag_bds_h3';
						  $sss4_h='flag_bds_h4';
						  $sss5_h='flag_bds_h5';
						  $sss6_h='flag_bds_h6';
						  $sss7_h='flag_bds_h7';
						
						  
						   $xxx1_w='flag_bdx_w1';
						  $xxx2_w='flag_bdx_w2';
						  $xxx3_w='flag_bdx_w3';
						  $xxx4_w='flag_bdx_w4';
						  $xxx5_w='flag_bdx_w5';
						  $xxx6_w='flag_bdx_w6';
						  $xxx7_w='flag_bdx_w7';
						  
						   $xxx1_h='flag_bdx_h1';
						  $xxx2_h='flag_bdx_h2';
						  $xxx3_h='flag_bdx_h3';
						  $xxx4_h='flag_bdx_h4';
						  $xxx5_h='flag_bdx_h5';
						  $xxx6_h='flag_bdx_h6';
						  $xxx7_h='flag_bdx_h7';
						  
						   $xxx1_color='flag_color1';
						  $xxx2_color='flag_color2';
						  $xxx3_color='flag_color3';
						  $xxx4_color='flag_color4';
						  $xxx5_color='flag_color5';
						  $xxx6_color='flag_color6';
						  $xxx7_color='flag_color7';
						
						 
						 
						  if($flag_jq==1&&$flag_qsb==1&&$flag_te_sx==1&&$flag_animal==1&&$flag_zds==1&&$flag_zdx==1&&$$xxx1==1&&$$xxx2==1&&$$xxx3==1&&$$xxx4==1&&$$xxx5==1&&$$xxx6==1&&$$xxx7==1&&$$sss1==1&&$$sss2==1&&$$sss3==1&&$$sss4==1&&$$sss5==1&&$$sss6==1&&$$sss7==1&&$$sss1_h==1&&$$sss2_h==1&&$$sss3_h==1&&$$sss4_h==1&&$$sss5_h==1&&$$sss6_h==1&&$$sss7_h==1&&$$xxx1_w==1&&$$xxx2_w==1&&$$xxx3_w==1&&$$xxx4_w==1&&$$xxx5_w==1&&$$xxx6_w==1&&$$xxx7_w==1&&$$xxx1_h==1&&$$xxx2_h==1&&$$xxx3_h==1&&$$xxx4_h==1&&$$xxx5_h==1&&$$xxx6_h==1&&$$xxx7_h==1&&$$xxx1_color==1&&$$xxx2_color==1&&$$xxx3_color==1&&$$xxx4_color==1&&$$xxx5_color==1&&$$xxx6_color==1&&$$xxx7_color==1||$k>10){
							
							
							   $flag=0;
							   }
							
							
						 
								
						   }while($flag==1);
					
					
					
					   for($i=1;$i<=7;$i++){
		                 $strx='b_ds'.$i;
			             if($$strx){	 
					     $s[]=$$strx;	
					      }
						  
						  $strbdx='b_dx'.$i;
			              if($$strbdx){	 
					       $s[]=$$strbdx;	
					      }
						  //合数
						    $strbds_h='b_ds_h'.$i;
			              if($$strbds_h){	 
					       $s[]=$$strbds_h;	
					      }
						    //合数大小
						    $strbdx_h='b_dx_h'.$i;
			              if($$strbdx_h){	 
					       $s[]=$$strbdx_h;	
					      }
						   //波色
						    $strbdx_color='b_color'.$i;
			              if($$strbdx_color){	 
					       $s[]=$$strbdx_color;	
					      }
						    //正码尾大小
						    $strbdx_w='b_dx_w'.$i;
			              if($$strbdx_w){	 
					       $s[]=$$strbdx_w;	
					      }
					   }
					 
					  
					   
						$s[]=$zh_ds;	
						    
					    $s[]=$zh_dx;
						//总和生肖单双
						$s[]=$zh_sx_ds;
						//特码天地生肖
						$s[]=$te_sx_td;
						//七色波
						$s[]=$qisebo;
						//家禽野兽
						$s[]=$te_sx_jq;
						
					
					   
						
						
						
					   $n_s=implode(";",$s);	
						
					  $insert_data['detail']=$n_s;	
						}
					
				
					$insert_result=M('lottery_results')->data($insert_data)->add();	
					
				 	if(!$insert_result){
						 
						 file_put_contents("test.txt", date("Y-m-d H:i:s") . "获取六合彩结果存入失败！" . "\r\n<br>", FILE_APPEND);  	
							}else{
						$hk6_result = new \Org\Util\Jshk6(); //香港六合彩
        $hk6_result->hk6_balance();
					}
 								
					}
					 
		return; 		
     }
	
 public function zh_zodiac($num){  //生肖
	$animal_array=$this->animal_array();
	
     foreach($num as $k=>$v){
		 $v=preg_replace('/^0+/','',$v);   //去除左边的0
		 foreach($animal_array as $kk=>$vv){
			 $number=explode(',',$vv['num']);
			  if(in_array($v,$number)){
				  $num[$k]=$vv['animal'];
			  }
		 }
		
	 }
	 $xs=implode(',',$num);
		return $xs;
 }
 //生肖归属
 public function animal_array(){
	 $animal='鼠>牛>虎>兔>龙>蛇>马>羊>猴>鸡>狗>猪';
	 $animal_array=explode('>',$animal);
	 $in[0]='1,13,25,37,49';
	 $in[1]='2,14,26,38';
	 $in[2]='3,15,27,39';
	 $in[3]='4,16,28,40';
	 $in[4]='5,17,29,41';
	 $in[5]='6,18,30,42';
	 $in[6]='7,19,31,43';
	 $in[7]='8,20,32,44';
	 $in[8]='9,21,33,45';
	 $in[9]='10,22,34,46';
	 $in[10]='11,23,35,47';
	 $in[11]='12,24,36,48';
	  
	 
	 $year=date('Y',time());
	
	 $my_animal = ($year-1900)%12;
	 $animal=$animal_array[$my_animal];
	 
	 foreach($animal_array as $k=>$v){
		 if($animal==$v){
			 $num=$k;
			 $k2=$k;
			 for($i=0;$i<=$num;$i++){
				 $kk=$k2;
				$animal_array_new[$i]['animal']=$animal_array[$kk]; 
				$animal_array_new[$i]['num']=$in[$i];
				$k2--;		
			 }
			
			$kkk=11;
			  for($i=$num+1;$i<=11;$i++){
				$animal_array_new[$i]['animal']=$animal_array[$kkk]; 
				$animal_array_new[$i]['num']=$in[$i]; 
				$kkk--;
			 }
			 
		 }
	 }
	
	 
	 return $animal_array_new;
 }
 public function zh_dx($sum){  //总和大小
      if($sum>=175){
		   $dx='大';	 
			 }else{
			 $dx='小';	 
				 }
		return $dx;
 }
  public function zh_w_dx($sum){  //总和尾大小
     $w=substr($sum,-1);

	 if($w>=5){
		   $dx='尾大';	 
			 }else{
			 $dx='尾小';	 
				 }
		return $dx;
 }
 

 public function zh_ds($sum){  //总和单双
      if($sum%2==0){
		$ds='双';
			}else{
		$ds='单';	 
		}
		return $ds;
 }
 public function bdx($num){  //正码大小
	 $bdx=array();
	 foreach($num as $k=>$v){
		 if($v>=25){
		   $bdx[$k]='大';	 
			 }else{
			$bdx[$k]='小';	 
				 }
 		 }
	return $bdx;	 
  }
   public function bdx_w($num){  //正码尾大小
	 $bdx=array();
	 foreach($num as $k=>$v){
		 $w=substr($v,-1);
		 if($w>=5){
		   $bdx[$k]='尾大';	 
			 }else{
			$bdx[$k]='尾小';	 
				 }
 		 }
	return $bdx;	 
  }
   public function bdx_h($num){  //正码合大小
	 $wdx=array();
	 foreach($num as $k=>$v){
		//个位
		 $g=$v%10;
		 $shi=$v/10%10;
		 $sum=$g+$shi;

	 if($sum>6){
		   $wdx[$k]='合大';	 
			 }else{
			 $wdx[$k]='合小';	 
				 }
		
 		 }
	return $wdx;	 
  }
 public function bds($num){  //正码单双
	 $bds=array();
	 foreach($num as $k=>$v){
		 if($v%2==0){
		   $bds[$k]='双';	 
			 }else{
			$bds[$k]='单';	 
				 }
 		 }
	return $bds;	 
  }	 
 public function bds_h($num){  //正码合数单双
	 $bds=array();
	 foreach($num as $k=>$v){
		 //个位
		 $g=$v%10;
		 $shi=$v/10%10;
		 $sum=$g+$shi;
		 if($sum%2==0){
		   $bds[$k]='合双';	 
			 }else{
			$bds[$k]='合单';	 
				 }
 		 }
	return $bds;	 
  }
  
 public function color($num){  //1-5球红波绿波蓝波
	 $bds=array();
	$red=array(01,02,07,08,12,13,18,19,23,24,29,30,34,35,40,45,46);
	$blue=array(03,04,09,10,14,15,20,25,26,31,36,37,41,42,47,48);
	$green=array(05,06,11,16,17,21,22,27,28,32,33,38,39,43,44,49);
	 foreach($num as $k=>$v){
		if(in_array($v,$red)){
			$bds[$k]='红波';
		}elseif(in_array($v,$green)){
			$bds[$k]='绿波';
		}else{
			$bds[$k]='蓝波';
		}
 		 }
	return $bds;	 
  }
  //总生肖单双
  public function animal_ds($animal){
	  
	  $array=explode(',',$animal);
	  $array=array_unique($array);
	  $count=count($array);
	  if($count%2==0){
		  $ds='双';
	  }else{
		  $ds='单';
	  }
	  return $ds;
  }
  //特码天地生肖
  public function te_sx($animal){
	  $array=explode(',',$animal);
	 
	  $te=$array[6];
	  if(in_array($te,array('兔','马','猴','猪','牛','龙' ))){
		  $te_sx='天';
	  }else{
		  $te_sx='地';
	  }
	  return $te_sx;
  }
  //特码家禽野兽
    public function te_jq($animal){
	  $array=explode(',',$animal);
	  $te=$array[6];
	  if(in_array($te,array('牛','马','羊','猪','鸡','狗'))){
		  $te_sx='家禽';
	  }else{
		  $te_sx='野兽';
	  }
	  return $te_sx;
  }
  //七色波
  public function qi_se($num){
	  
	  $red=array(01,02,07,08,12,13,18,19,23,24,29,30,34,35,40,45,46);
	$blue=array(03,04,09,10,14,15,20,25,26,31,36,37,41,42,47,48);
	$green=array(05,06,11,16,17,21,22,27,28,32,33,38,39,43,44,49);
	$red_f=0;
	$blue_f=0;
	$green_f=0;
	foreach($num as $k=>$v){
		if(in_array($v,$red)){
			$red_f+=1;
			if($k==6){
			$red_f+=0.5;	
			}
		}elseif(in_array($v,$green)){
			$green_f+=1;
			if($k==6){
			$green_f+=0.5;	
			}
		}else{
		 $blue_f+=1;
			if($k==6){
			$green_f+=0.5;	
			}		 
		}
	}
	if($red_f>$green_f&&$red_f>$blue_f){
		$color='红波';
	}elseif($green_f>$red_f&&$green_f>$blue_f){
		$color='绿波';
	}else{
		$color='蓝波';
	}
	
	return $color;
	  
  }
	 
}